package org.lanqiao.service.impl;

import org.lanqiao.dao.WxuserDao;
import org.lanqiao.entity.Wxuser;
import org.lanqiao.service.WxuserService;
import org.lanqiao.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class WxuserServiceImpl implements WxuserService {

    @Autowired
    WxuserDao wxuserDao;


    /**
     * @Author 王宇
     * @Description //TODO 查询单个用户
     * @Date 2019/06/11 9:30
     * @Param [wxId]
     * @return org.lanqiao.entity.Wxuser
     */
    @Override
    public Result getWxUser(String wxId) {
        try {
            Result result = new Result();
            Wxuser wxUser = wxuserDao.getWxUser(wxId);
            if(wxUser != null){
                result.setCode(0);
                result.setMsg("成功");
                result.setData(wxUser);
            }else{
                result.setCode(1);
                result.setMsg("失败");
            }
            return result;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }


    /**
      * @Author 徐金星
      * @Description //新增微信用户
      * @Date 2019/6/12 14:49
      * @Param [wxuser]
      * @explain
      * @return org.lanqiao.util.Result
      */
    @Override
    
    public Result addWxUser(Wxuser wxuser) {
        Result result=new Result();
        if (wxuser.getWxHead()==null||wxuser.getWxName()==null){
            result.setCode(1);
            result.setMsg("失败");
            result.setData(wxuser);
            return result;
        }else {
            wxuserDao.addWxUser(wxuser);
            result.setCode(0);
            result.setMsg("成功");
            result.setData(wxuser);
            return result;
        }

    }

}
